package cn.wolfcode.restful.controller;

import cn.wolfcode.restful.domain.Employee;
import cn.wolfcode.restful.util.JsonResult;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.*;

import java.util.Arrays;
import java.util.List;

@Controller
@RestController // 等价于 : @Controller + ResponseBody
@RequestMapping("/employees")
public class EmployeeController_bak {
    @GetMapping
    public List<Employee> list(){
        return Arrays.asList(new Employee(1L,18,"dasha"),
                new Employee(2L,16,"ersha"));
    }

    @PostMapping
    public Employee save(Employee employee){
        employee.setId(3L);
        return employee;
    }

    @PutMapping
    public Employee update (Employee employee){
        employee.setName(employee.getName() + "hahaha");
        return employee;
    }

    @DeleteMapping
    public JsonResult delete(Long id){
        return JsonResult.success(id);
    }


    @GetMapping(value = "/{id}")
    public Employee detail(@PathVariable Long id){
        return new Employee(id,18,"dasha");
    }
}
